//
//  ZJVisiorView.swift
//  Webo
//
//  Created by 曾静 on 16/6/25.
//  Copyright © 2016年 qq. All rights reserved.
//

import UIKit
import SnapKit
protocol ZJVisiorViewDeleagte:NSObjectProtocol{
    
    func modalOauthView()
}

class ZJVisiorView: UIView {

    weak var myDelegate1: ZJVisiorViewDeleagte?
    var hehe:(()->())?
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
         self.backgroundColor = RGB(237, green: 237, blue: 237)
        
        setFrame()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setFrame(){
        
        
        addSubview(circleImageView)
        addSubview(coverImageView)
        addSubview(loginButton)
        addSubview(registerButton)
        addSubview(desLabel)
        addSubview(hourseImageView)
        
        circleImageView .snp_makeConstraints { (make) -> Void in
            
            make.center.equalTo(self)
        }
        
        coverImageView .snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
    
        }
        
        hourseImageView .snp_makeConstraints { (make) -> Void in
             make.center.equalTo(self)
        }
        
        desLabel .snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(coverImageView.snp_bottom).offset(16)
            make.width.equalTo(224)
            make.height.equalTo(36)
            make.centerX.equalTo(self)
        }
        
        loginButton .snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(desLabel)
            
            make.top.equalTo(desLabel.snp_bottom).offset(16)
            
            make.size.equalTo(CGSizeMake(100, 36))
        }
        
        registerButton .snp_makeConstraints { (make) -> Void in
            
            make.right.equalTo(desLabel)
            
            make.top.equalTo(desLabel.snp_bottom).offset(16)
            
            make.size.equalTo(CGSizeMake(100, 36))
        }
    
    }
    
    
    func setVisorViewInfo(imageName:String?,desTitle:String?){
        
        guard let image = imageName,let des = desTitle else{
            
//            只是在首页加了动画
            
            addAnmiation()
            
            return
        }
        
        circleImageView.hidden = true;
        
        coverImageView.hidden = true;
        
        
        
        hourseImageView.image = UIImage(named:image)
        
        desLabel.text = des
        
        
        
    }
    
    
    func addAnmiation(){
        
        let ca :CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation")
        
        ca.toValue = M_PI * 2
        
        ca.repeatCount = MAXFLOAT
        
        ca.duration = 20
        
        ca.removedOnCompletion = false
        
        circleImageView.layer .addAnimation(ca, forKey: nil)
        
        
    }
    
    //懒加载创建UI控件
    private lazy var circleImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
    
    private lazy var coverImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
    
    private lazy var hourseImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
    
    private lazy var desLabel:UILabel = {
        
        let lab = UILabel()
        
        lab.textColor = UIColor.darkGrayColor()
        
        lab.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        
        lab.font = UIFont.systemFontOfSize(14)
        
        lab.numberOfLines = 0
        
        lab.textAlignment = .Center
        
        return lab
        
    }()
    
    private lazy var loginButton:UIButton = {
        
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        btn.addTarget(self, action: "loginBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        btn.setTitle("登录", forState: UIControlState.Normal)
        
        btn.setTitleColor(ThemeColor, forState: UIControlState.Highlighted)
        
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)

        
        return btn
        
    }()
    
    private lazy var registerButton:UIButton = {
        
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        btn.addTarget(self, action: "loginBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        btn.setTitle("注册", forState: UIControlState.Normal)
        
        btn.setTitleColor(ThemeColor, forState: UIControlState.Highlighted)
        
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        return btn
        
    }()
    
    @objc private func loginBtnClick(){
        
       
        hehe?()
        myDelegate1?.modalOauthView()
        print(myDelegate1)
        
    }
    
    

}
